//
//  overlappingConstructorsFunc.hpp
//  learnC++
//
//  Created by apple on 2018/6/3.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef overlappingConstructorsFunc_hpp
#define overlappingConstructorsFunc_hpp

#include <stdio.h>
#include <iostream>

//重叠构造函数

class overlappingClass {
    
public:
    overlappingClass(){
        printf("default init\n");
        //code A
    }
//    C++11之前会导致意外行为，一般使用下面类的处理方式
//    C++11之后正式才支持，方可使用
    overlappingClass(int value):overlappingClass(){
        
        printf("param init\n");
        //code B
        //这样可以避免重复写code A代码
    }
    
};


class Overlapping {
    
private:
    void DoA(){
        //code A
    }
    
public:
    Overlapping(){
        printf("default init\n");
        DoA();
    }
    Overlapping(int value){
        
        printf("param init\n");
        DoA();
        //code B
        //这样也可以避免重复写code A代码
    }
    
};

class OverlappingTwo{

private:
    int m_id;
    std::string m_name;
    
public:
    OverlappingTwo(int value = 10,std::string name = ""):m_id(value),m_name(name){
        std::cout << m_id << "/" << m_name << "\n";
    }
    
    //委托构造方法
    OverlappingTwo(const std::string &name):OverlappingTwo(0,name){
        std::cout << m_id << "/" << m_name << "\n";
    }
    
};

#endif /* overlappingConstructorsFunc_hpp */
